﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BCCommon;
using BCDto.OA.AuxiliaryRule;
using BCService.OA.AuxiliaryRule;
using BCService.Utils;
using BlackCoffeeRESTful.Configs;

namespace BlackCoffeeRESTful.Controllers.Management.OA.AuxiliaryRule
{
    /// <summary>
    /// OA系统辅助规则
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class AuxiliaryRuleController : ManagementBaseController
    {
        private readonly IAuxiliaryRuleService auxiliaryRuleService;

        public AuxiliaryRuleController(IAuxiliaryRuleService auxiliaryRuleService)
        {
            this.auxiliaryRuleService = auxiliaryRuleService;
        }

        #region 添加OA系统辅助规则
        /// <summary>
        ///  添加OA系统辅助规则
        /// </summary>
        /// <param name="requestDto">OA系统辅助规则信息</param>
        /// <response code="201">添加OA系统辅助规则成功</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加OA系统辅助规则")]
        [ProducesResponseType(typeof(AuxiliaryRuleDto), 201)]
        public IActionResult Post(
            [FromBody]AuxiliaryRuleRequestDto requestDto)
        {
            var result = this.auxiliaryRuleService.Add(requestDto);
            return this.Created(string.Format("api/v1/sim/AuxiliaryRule/{0}", result.AuxiliaryRuleId), result);
        }
        #endregion

        #region 修改OA系统辅助规则
        /// <summary>
        ///  修改OA系统辅助规则
        /// </summary>
        /// <param name="auxiliaryRuleId">OA系统辅助规则Id</param>
        /// <param name="requestDto">OA系统辅助规则信息</param>
        /// <response code="200">修改OA系统辅助规则成功</response>
        /// <returns></returns>
        [HttpPut("{auxiliary_rule_id}")]
        [Log("修改OA系统辅助规则")]
        [ProducesResponseType(typeof(AuxiliaryRuleDto), 200)]
        public IActionResult Post([FromRoute(Name = "auxiliary_rule_id")]long auxiliaryRuleId, [FromBody]AuxiliaryRuleRequestDto requestDto)
        {
            AuxiliaryRulePutDto putDto = requestDto.As<AuxiliaryRulePutDto>();
            putDto.AuxiliaryRuleId = auxiliaryRuleId;
            return this.Ok(this.auxiliaryRuleService.Update(putDto));
        }
        #endregion

        #region 删除OA系统辅助规则
        /// <summary>
        ///  删除OA系统辅助规则
        /// </summary>
        /// <param name="auxiliaryRuleId">OA系统辅助规则Id</param>
        /// <response code="204">删除OA系统辅助规则成功</response>
        /// <returns></returns>
        [HttpDelete("{auxiliary_rule_id}")]
        [Log("删除OA系统辅助规则")]
        public IActionResult Delete([FromRoute(Name = "auxiliary_rule_id")]long auxiliaryRuleId)
        {
            this.auxiliaryRuleService.Delete(auxiliaryRuleId);
            return this.NoContent();
        }
        #endregion

        #region 获取OA系统辅助规则
        /// <summary>
        ///  获取OA系统辅助规则
        /// </summary>
        /// <param name="auxiliaryRuleId">OA系统辅助规则Id</param>
        /// <response code="200">获取OA系统辅助规则</response>
        /// <returns></returns>
        [HttpGet("{auxiliary_rule_id}")]
        [ProducesResponseType(typeof(AuxiliaryRuleDto), 200)]
        public IActionResult Get([FromRoute(Name = "auxiliary_rule_id")]long auxiliaryRuleId)
        {
            return this.Ok(this.auxiliaryRuleService.GetEntity(auxiliaryRuleId));
        }
        #endregion

        #region 获取OA系统辅助规则列表
        /// <summary>
        ///  获取OA系统辅助规则列表
        /// </summary>
        /// <response code="200">获取OA系统辅助规则列表</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(AuxiliaryRuleDto), 200)]
        public IActionResult Get()
        {
            return this.Ok(this.auxiliaryRuleService.GetList());
        }
        #endregion

        #region 获取OA系统辅助规则（分页）
        /// <summary>
        ///  获取OA系统辅助规则（分页）
        /// </summary>
        /// <param name="auxiliaryRuleName">OA系统辅助规则名称</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="pageIndex">以 1 起始的页码 (默认 1)。</param>
        /// <param name="pageSize">每页要显示的行数 (默认 10)。</param>
        /// <response code="200">获取OA系统辅助规则（分页）</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<AuxiliaryRuleDto>), 200)]
        public IActionResult Query([FromQuery(Name = "auxiliary_rule_name")]string auxiliaryRuleName,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            int pageIndex = 1,
            int pageSize = 10)
        {
            return this.Ok(this.auxiliaryRuleService.Query(auxiliaryRuleName, start, end, pageIndex, pageSize));
        }
        #endregion

    }
}
